//
//  WmcTeamCloudFilterView.swift
//  YPWatermarkCamera
//
//  Created by yupao_ios_macmini06 on 2022/9/13.
//

import UIKit

class WmcTeamCloudFilterView: WmcBaseView {
    private var dayModel: String?

    override func makeUI() {
        addSubview(dateView)
        addSubview(searchBtn)
        addSubview(line)

        isUserInteractionEnabled = true

        searchBtn.snp.makeConstraints { make in
            make.right.equalTo(-16)
            make.width.equalTo(80)
            make.height.equalTo(36)
            make.centerY.equalToSuperview()
        }

        dateView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.centerY.equalToSuperview()
            make.top.equalTo(12)
            make.bottom.equalTo(-12)
            make.height.equalTo(40)
            make.right.equalTo(searchBtn.snp.left).offset(-16)
        }

        line.snp.makeConstraints { make in
            make.height.equalTo(0.5)
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview()
        }

        dateView.addSubview(dateIconImageView)
        dateView.addSubview(dateLabel)
        dateView.addSubview(dateBtn)

        dateIconImageView.snp.makeConstraints { make in
            make.left.equalTo(12)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(20)
        }

        dateLabel.snp.makeConstraints { make in
            make.left.equalTo(dateIconImageView.snp.right).offset(6)
            make.centerY.equalToSuperview()
            make.height.equalTo(20)
            make.right.equalTo(dateBtn.snp.left).offset(-10)
        }

        dateBtn.snp.makeConstraints { make in
            make.width.height.equalTo(12)
            make.right.equalTo(-12)
            make.centerY.equalToSuperview()
        }
    }

    func configure(dayModel: String) {
        self.dayModel = dayModel
        dateLabel.text = dayModel
    }

    func cleanDate() {
        dayModel = nil
    }

    lazy var dateView: UIView = {
        let view = UIView()
        view.backgroundColor = .wmc_grayH19_F5F5F5
        view.layer.cornerRadius = 4
        return view
    }()

    lazy var searchBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage("search".wmc_image.yp.set(tintColor: UIColor.wmc_white_FFFFFF), for: .normal)
        btn.setTitle("照片", for: .normal)
        btn.setTitleColor(.wmc_white_FFFFFF, for: .normal)
        btn.titleLabel?.font = 16.wmc_font
        btn.backgroundColor = .wmc_mainTheme
        btn.layer.cornerRadius = 4
        return btn
    }()

    private lazy var line: UIView = {
        let view = UIView()
        view.backgroundColor = .wmc_grayH15_E6E6E6
        return view
    }()

    private lazy var dateIconImageView: UIImageView = {
        let view = UIImageView(image: "cloud_calendar".wmc_image)
        return view
    }()

    private lazy var dateLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
        label.text = Date().yp.string("yyyy年MM月dd日")
        return label
    }()

    lazy var dateBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage("triangle_bottom".wmc_image, for: .normal)
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        return btn
    }()
}
